﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace UI.Forms
{
    /// <summary>
    /// 开卡单据列表
    /// </summary>
    public partial class ProductSale_DList : FormBase1
    {
        public ProductSale_DList()
        {
            InitializeComponent();
        }

        private void opencardList_Load(object sender, EventArgs e)
        {
            BindingList<SVC.client.View_Emp_lite> emps=my.bw.View_Emp_lite_List("",my.ACID);
            dateselect1.lue_date.Properties.DataSource = my.dts;
            lue_client.Properties.DataSource = my.bw.View_Client_lite_List(false, my.ACID);
            lue_client.Properties.DisplayMember = "ClientName";
            lue_client.Properties.ValueMember = "ClientID";
            lue_js.Properties.DataSource = emps;
            lue_js.Properties.DisplayMember = "EmpName";
            lue_js.Properties.ValueMember = "EmplID";
            lue_op.Properties.DataSource = emps;
            lue_op.Properties.DisplayMember = "EmpName";
            lue_op.Properties.ValueMember = "EmplID";
            dateselect1.lue_date.EditValue = 1;
        }

        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn_search_Click(object sender, EventArgs e)
        {
            BindDate();
        }

        private void BindDate()
        {
            DateTime? sd = null;
            DateTime? ed = null;
            if (dateselect1.de_sd.EditValue != null)
            { sd = dateselect1.de_sd.DateTime; }
            if (dateselect1.de_ed.EditValue != null)
            { ed = dateselect1.de_ed.DateTime; }

            Guid? clientid = null;
            Guid? opid = null;
            Guid? jsid = null;
            if (lue_client.EditValue != null) clientid = new Guid(lue_client.EditValue.ToString());
            if (lue_op.EditValue != null) opid = new Guid(lue_op.EditValue.ToString());
            if (lue_js.EditValue != null) jsid = new Guid(lue_js.EditValue.ToString());

            gridControl1.DataSource = my.bw.Get_ProductSale_D_List(sd, ed, opid, jsid, clientid, my.ACID);
        }

        /// <summary>
        /// 清楚条件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn_Clean_Click(object sender, EventArgs e)
        {
            dateselect1.de_sd.EditValue = dateselect1.de_ed.EditValue = lue_client.EditValue = lue_js.EditValue = lue_op.EditValue = null;
            BindDate();
        }

        private void gridView1_RowClick(object sender, DevExpress.XtraGrid.Views.Grid.RowClickEventArgs e)
        {
            if (e.RowHandle>=0)
            {
                //SVC.client.View_ProductSale_D_List vm = gridView1.GetRow(e.RowHandle) as SVC.client.View_ProductSale_D_List;
                //SVC.client.CardOpen_M m = my.bw.CardOpen_MBypid_Get(vm.pid, my.ACID);
                //m.CardOpen_D = my.bw.CardOpen_D_Bypid_Get(vm.pid, my.ACID);
                //openCard frm = new openCard(m);
                //frm.ShowDialog();
            }
        }
    }
}